package main.service;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;

import main.dao.ReplyDAO;
import main.dao.UserDAO;
import main.entity.ReplyVO;
import main.entity.UserVO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("replyService")
public class ReplyService extends BaseService<ReplyVO> {
	
	@Autowired
	private ReplyDAO replyDAO;
	@Autowired
	private UserDAO userDAO;

	@Override
	public Integer save(ReplyVO replyVO){
		replyVO.setReply_time(new Date(new java.util.Date().getTime()));
		return getBaseDAO().save(replyVO);
	}
	
	@SuppressWarnings("unchecked")
	public List<ReplyVO> getReplyByThreadsID(Integer threadsID){
		List<ReplyVO> replysByThreads = (List<ReplyVO>) replyDAO.getReplyByThreadsID(threadsID);
		for (ReplyVO replyVO : replysByThreads) {
			Serializable uID = replyVO.getuID();
			UserVO userVO = userDAO.getByID(UserVO.class, uID);
			String unm = userVO.getUsername();
			replyVO.setUnm(unm);
		}
		return replysByThreads;
	}
	
}
